<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改问题')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-dfQuestion-edit" th:object="${dfQuestion}">
            <input id="id" name="id" th:field="*{id}"  type="hidden">
			<div class="form-group">	
				<label class="col-sm-3 control-label">用户名称：</label>
				<div class="col-sm-8">
					<input id="userName" name="userName" th:field="*{userName}" class="form-control" type="text" readonly>
				</div>
			</div>
			<div class="form-group" style="display: none">
				<label class="col-sm-3 control-label">用户id：</label>
				<div class="col-sm-8">
					<input id="userId" name="userId" th:field="*{userId}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">用户单位：</label>
				<div class="col-sm-8">
					<input id="userDept" name="userDept" th:field="*{userDept}" class="form-control" type="text" readonly>
				</div>
			</div>
			<div class="form-group" style="display: none">
				<label class="col-sm-3 control-label">用户单位id：</label>
				<div class="col-sm-8">
					<input id="userDeptId" name="userDeptId" th:field="*{userDeptId}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group" style="display: none">
				<label class="col-sm-3 control-label">联系方式：</label>
				<div class="col-sm-8">
					<input id="userPhone" name="userPhone" th:field="*{userPhone}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="questionAnswer" name="questionAnswer" class="form-control" type="text" th:field="*{questionAnswer}">
				</div>
			</div>
			<div class="form-group" style="display: none">
				<label class="col-sm-3 control-label">问题处理结果：</label>
				<div class="col-sm-8">
					<input id="questionState" name="questionState" th:field="*{questionState}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">问题类型：</label>
				<div class="col-sm-8" style="padding-top: 3px;">
					<select name="questionType" class="form-control">
						<option value="2"  th:field="*{questionType}">处理</option>
						<option value="3"  th:field="*{questionType}">解释</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">问题版本号：</label>
				<div class="col-sm-8" >
					<select name="questionVersion" class="form-control" th:with="type=${@dict.getType('df_question_version')}">
						<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"  th:field="*{questionVersion}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">问题标题：</label>
				<div class="col-sm-8">
					<input id="questionTitle" name="questionTitle" th:field="*{questionTitle}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">内容描述：</label>
				<div class="col-sm-8">
					<textarea id="questionContent" name="questionContent" th:field="*{questionContent}" class="form-control" rows="5" style="resize:none;"></textarea>
				</div>
			</div>
			<div class="form-group" >
				<label class="col-sm-3 control-label">附件：</label>
				<div class="col-sm-8">
					<ul th:each="file,fileStat : ${dfQuestion.files}" style="padding-left: 0px;">
						<img class="question_imgFile" th:src="${file.fileId}" th:if="${file.fileType=='png'||file.fileType=='jpg'}">
						<img th:src="@{/img/tb_word.png}" th:if="${file.fileType=='docx'||file.fileType=='doc'}">
						<img th:src="@{/img/tb_excel.png}" th:if="${file.fileType=='xls'||file.fileType=='xlsx'}">
						<img th:src="@{/img/tb_zip.png}" th:if="${file.fileType=='zip'||file.fileType=='rar'}">
						<img th:src="@{/img/tb_ppt.png}" th:if="${file.fileType=='ppt'||file.fileType=='pptx'}">
					</ul>
				</div>
			</div>
			<div id="outerdiv" style="position:fixed;top:0;left:0;background:rgba(0,0,0,0.7);z-index:2;width:100%;height:100%;display:none;">
				<div id="innerdiv" style="position:absolute;">
					<img id="bigimg" style="border:5px solid #fff;" src="" />
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-8">
					<input id="questionStart" name="questionStart" class="form-control" type="hidden" th:field="*{questionStart}">
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">上传附件：</label>
				<input type="file" accept="image/*" onchange="uploadFile()" id="fileUpload" multiple="multiple" style="display: none"/>
				<div class="col-sm-8">
					<!--<ul class="question_addfail_ul" id="lid">-->
					<!--<li><img id="img0" src=""><button class="question_delete"></button></li>-->

					<!--</ul>-->
					<ul id="lid"></ul>
					<ul>
						<li><button type="button" class="question_addfail"onclick="upload()"></button></li>
					</ul>

				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "question/dfQuestion";
        var prefis = ctx + "question/dfFile"
        var preFile = "http://211.149.205.33:18080/file/";
        var id =$("#id").val(); //获取id
		$("#form-dfQuestion-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-dfQuestion-edit').serialize(),saveCallback);
	        }
	    }
        function saveCallback(result) {
            var question_id = result.data;
            addFile(question_id) //上传
        }
        function upload() {
            $("#fileUpload").click()
        }
        var arr =[];  //定义一个数组
	    //初始化图片
		$(function(){
            $(".question_imgFile").width($(".col-sm-8").width());
		})

        function uploadFile(){		 //上传
            var file = $("#fileUpload").get(0).files[0];
            if(file != undefined){
                var formData = new FormData();
                formData.append("files", file);
                $.ajax({
                    url:preFile+"mulitiupload",
                    type: "POST",
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function(resp) {
                        var model=new Object();
                        model.fileId =resp[0].fileid; //文件id
                        model.fileName =resp[0].name;//文件名称
                        var index = model.fileName.lastIndexOf(".");
                        var suffix = model.fileName.substring(index+1);
                        model.fileType =suffix; //文件类型
                        arr.push(model);
                        if(suffix=="png" || suffix=="jpg"){
                            $("#lid").append('<img src="'+preFile+"img/"+model.fileId+'" id="img0" >').append(" ");
                        }
                        if(suffix=="xls" || suffix=="xlsx"){
                            $("#lid").append('<img src="'+preFile+"img/"+190916001140350+'" id="img0" >').append(" ");
                        }
                        if(suffix=="docx"|| suffix=="doc"){
                            $("#lid").append('<img src="'+preFile+"img/"+190916001206935+'" id="img0" >').append(" ");
                        }
                        if(suffix=="zip" || suffix=="rar"){
                            $("#lid").append('<img src="'+preFile+"img/"+190916001125877+'" id="img0" >').append(" ");
                        }
                        if(suffix=="ppt" || suffix=="pptx"){
                            $("#lid").append('<img src="'+preFile+"img/"+190916091106432+'" id="img0" >').append(" ");
                        }
                    },
                    error: function(error) {
                        $.modal.alertWarning("附件上传失败。");
                    }
                });
            } else {
                $.modal.alertWarning("服务出现错误 。联系管理员 ");
            }
        };

        function addFile(){
            $.ajax({
                url:prefis+"/editFile",
                type: "POST",
                data: {questionId:id,array:JSON.stringify(arr)},
                dataType:"json",
                success: function(resp) {
                }
            });
        }
        //点击图片 在弹出层显示大图
        $(function(){
            $(".question_imgFile").click(function(){
                var _this = $(this);//将当前的pimg元素作为_this传入函数
                imgShow("#outerdiv", "#innerdiv", "#bigimg", _this);
            });
        });
        function imgShow(outerdiv, innerdiv, bigimg, _this){
            var src = _this.attr("src");//获取当前点击的pimg元素中的src属性
            $(bigimg).attr("src", src);//设置#bigimg元素的src属性

            /*获取当前点击图片的真实大小，并显示弹出层及大图*/
            $("<img/>").attr("src", src).load(function(){
                var windowW = $(window).width();//获取当前窗口宽度
                var windowH = $(window).height();//获取当前窗口高度
                var realWidth = this.width;//获取图片真实宽度
                var realHeight = this.height;//获取图片真实高度
                var imgWidth, imgHeight;
                var scale = 0.8;//缩放尺寸，当图片真实宽度和高度大于窗口宽度和高度时进行缩放

                if(realHeight>windowH*scale) {//判断图片高度
                    imgHeight = windowH*scale;//如大于窗口高度，图片高度进行缩放
                    imgWidth = imgHeight/realHeight*realWidth;//等比例缩放宽度
                    if(imgWidth>windowW*scale) {//如宽度扔大于窗口宽度
                        imgWidth = windowW*scale;//再对宽度进行缩放
                    }
                } else if(realWidth>windowW*scale) {//如图片高度合适，判断图片宽度
                    imgWidth = windowW*scale;//如大于窗口宽度，图片宽度进行缩放
                    imgHeight = imgWidth/realWidth*realHeight;//等比例缩放高度
                } else {//如果图片真实高度和宽度都符合要求，高宽不变
                    imgWidth = realWidth;
                    imgHeight = realHeight;
                }
                $(bigimg).css("width",imgWidth);//以最终的宽度对图片缩放

                var w = (windowW-imgWidth)/2;//计算图片与窗口左边距
                var h = (windowH-imgHeight)/2;//计算图片与窗口上边距
                $(innerdiv).css({"top":h, "left":w});//设置#innerdiv的top和left属性
                $(outerdiv).fadeIn("fast");//淡入显示#outerdiv及.pimg
            });

            $(outerdiv).click(function(){//再次点击淡出消失弹出层
                $(this).fadeOut("fast");
            });
        }
	</script>
</body>
</html>
